package view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import model.Group;
import controller.DeleteGroup;
import controller.EditGroup;


@SuppressWarnings("serial")
public class PanelGroupDetails extends JPanel {

	private static PanelGroupDetails single;

	private Group currentGroup;
	private String Group_Name;
	JTable AbsenceList = new JTable();
	JScrollPane JSP = new JScrollPane(AbsenceList);

	private JButton JBWijzig = new JButton("Wijzig");
	private JButton JBDelete = new JButton("Verwijder");
	private JButton JBDeleteConfirm = new JButton("Bevestigen");
	private JButton JBopslaan = new JButton("Opslaan");
	private JButton JBannuleren = new JButton("Annuleren");

	private JTextField JTname = new JTextField("");

	private JLabel JLName = new JLabel();
	private JLabel JLKlas = new JLabel("Klas:");
	private JLabel JLAbsenties = new JLabel("<html>hier komen de absenties<br/>van de klas</html>");

	private PanelGroupDetails() {

		setBounds(0, 0, 860, 720);
		setLayout(null);

		JBWijzig.setBounds(20, 200, 150, 30);
		JBopslaan.setBounds(20, 200, 150, 30);
		JBDelete.setBounds(180, 200, 150, 30);
		JBDeleteConfirm.setBounds(180, 200, 150, 30);
		JBannuleren.setBounds(180, 200, 150, 30);

		JLName.setBounds(100, 100, 100, 30);
		JLKlas.setBounds(40, 100, 100, 30);
		JLAbsenties.setBounds(450, 50, 200, 300);
		JTname.setBounds(100, 100, 200, 30);
		AbsenceList.setBounds(400, 100, 300, 500);
		JSP.setBounds(400, 100, 300, 500);

		JLName.setVisible(true);
		JLKlas.setVisible(true);
		JLAbsenties.setVisible(true);

		JBopslaan.setVisible(false);
		JTname.setVisible(false);
		JBannuleren.setVisible(false);
		
		JBDeleteConfirm.setVisible(false);
		JBDeleteConfirm.setBackground(Color.RED);

		JBopslaan.addActionListener(new EditGroup(this));
		JBWijzig.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				JLKlas.setVisible(true);
				JTname.setVisible(true);
				JBopslaan.setVisible(true);
				JBannuleren.setVisible(true);

				JLName.setVisible(false);
				JBWijzig.setVisible(false);
				JBDelete.setVisible(false);
				JBDeleteConfirm.setVisible(false);

			}

		});
		
		JBDelete.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JBDelete.setVisible(false);
				JBDeleteConfirm.setVisible(true);
				
			}
		});
		JBDeleteConfirm.addActionListener(new DeleteGroup(this));
		JBDeleteConfirm.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JBDelete.setVisible(true);
				JBDeleteConfirm.setVisible(false);
				
			}
		});

		JBannuleren.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				JBDelete.setVisible(true);
				JBDeleteConfirm.setVisible(true);
				JBWijzig.setVisible(true);
				JLName.setVisible(true);
				JLKlas.setVisible(true);

				JBopslaan.setVisible(false);
				JTname.setVisible(false);
				JBannuleren.setVisible(false);
				JBDeleteConfirm.setVisible(false);

			}
		});

		add(JBWijzig);
		add(JBDelete);
		add(JBDeleteConfirm);
		// add(JBSwitch);
		add(JBannuleren);

		add(JLKlas);
		add(JLName);
		//JSP.add(AbsenceList);
		//add(JSP);
		add(JTname);
		add(JBopslaan);
		add(JLAbsenties);
	}

	public static PanelGroupDetails getInstance() {
		if (single == null) {
			single = new PanelGroupDetails();
		}
		return single;
	}

	public void selfDestroy() {
		single = null;
	}

	public JTextField getJTName() {
		return JTname;
	}

	public void setName(JTextField JTname) {
		this.JTname = JTname;
	}

	public JLabel getJLName() {
		return JLName;
	}

	public String getGroup_Name() {
		return Group_Name;
	}

	public void setGroup_Name(String group_Name) {
		Group_Name = group_Name;
	}

	public Group getCurrentGroup() {
		return currentGroup;
	}

	public void setCurrentGroup(Group currentGroup) {
		this.currentGroup = currentGroup;
	}

	public JButton getJBWijzig() {
		return JBWijzig;
	}

	public void setJBWijzig(JButton jBWijzig) {
		JBWijzig = jBWijzig;
	}

	public JButton getJBopslaan() {
		return JBopslaan;
	}

	public void setJBopslaan(JButton jBopslaan) {
		JBopslaan = jBopslaan;
	}

	public JButton getJBannuleren() {
		return JBannuleren;
	}

	public void setJBannuleren(JButton jBannuleren) {
		JBannuleren = jBannuleren;
	}

	public JTextField getJTname() {
		return JTname;
	}

	public void setJTname(JTextField jTname) {
		JTname = jTname;
	}

	public JLabel getJLKlas() {
		return JLKlas;
	}

	public void setJLKlas(JLabel jLKlas) {
		JLKlas = jLKlas;
	}

	public JScrollPane getJSP() {
		return JSP;
	}

	public void setJSP(JScrollPane jSP) {
		JSP = jSP;
	}

	public void setJLName(JLabel jLName) {
		JLName = jLName;
	}

	public void updateGroupDetail(Group g) {
		currentGroup = g;
		JLName.setName(g.getGroup_name());
	}

	public Group getGroup() {
		return currentGroup;
	}

	public JButton getJBDelete() {
		return JBDelete;
	}

}
